package cn.lcsjsxy.yxz.day.Thread;

//线程安全
public class Threadsafe {
    public static void main(String[] args) {

        //什么是线程安全
        //多个线程程序在并发执行时,修改了共享内存中共享对象的属性,导致的数据冲突问题
        User1 user = new User1();

        Thread t1 = new Thread(()->{
            user.name = "123";
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(user.name);
        });
        Thread t2 = new Thread(()->{
            user.name = "456";
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(user.name);
        });
        t1.start();
        t2.start();

        System.out.println("main线程执行完毕");

    }
}
class User1{
    public String name;
}